package com.ztewatch.wearcontacts;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.SimpleAdapter;

public class WearContactSelImgActivity extends Activity {
	private GridView mGridView;
	public static int[] imageIds = new int[] { R.drawable.ic_address_portrait,
			R.drawable.ic_family, R.drawable.ic_friends, R.drawable.ic_address_portrait,
			R.drawable.ic_address_portrait, R.drawable.ic_address_portrait, R.drawable.ic_address_portrait,
			R.drawable.ic_address_portrait, R.drawable.ic_address_portrait, R.drawable.ic_address_portrait };
	public static final String IMAGE_INDEX = "imageids_index";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_wear_contact_sel_img);
		mGridView = (GridView) findViewById(R.id.selimg_gridview);
		List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < imageIds.length; i++) {
			Map<String, Object> listItem = new HashMap<String, Object>();
			listItem.put("image", imageIds[i]);
			listItems.add(listItem);
		}
		SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems,
				R.layout.selimg_cell, new String[] { "image" },
				new int[] { R.id.image1 });
		mGridView.setAdapter(simpleAdapter);
		mGridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Intent intent = getIntent();
				Bundle bundle = new Bundle();
				bundle.putInt(IMAGE_INDEX, position);
				intent.putExtras(bundle);
				setResult(RESULT_OK, intent);
				finish();
			}

		});
	}
}
